package com.lemon.smartsafety.ui.adapter.fire;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ldzs.recyclerlibrary.swipe.SwipeMenuLayout;
import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.AppService;
import com.lemon.smartsafety.entity.fire.FireCompanyDelete;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafety.result.fire.SuperviseSettingTail;
import com.lemon.smartsafety.ui.adapter.address.AddressContactAdapter;
import com.lemon.smartsafety.utils.CommonUtil;
import com.lemon.smartsafety.utils.common.LoggerHelper;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * 项目名称：workspace
 * 类描述：
 * 创建人：Fargo
 * 创建时间：2016/8/11 16:00
 * 修改人：Fargo
 * 修改时间：2016/8/11 16:00
 * 修改备注：
 */
public class FirefightingSetAdapter extends LemonRcvAdapter<SuperviseSettingTail> {

    private LoggerHelper loggerHelper = new LoggerHelper(AddressContactAdapter.class);


    private RecyclerTClickListener<SuperviseSettingTail> mListener;

    public FirefightingSetAdapter(@Nullable List<SuperviseSettingTail> data) {
        super(data);
    }

    public FirefightingSetAdapter(List<SuperviseSettingTail> data, RecyclerTClickListener<SuperviseSettingTail> listener) {
        super(data);
        this.mListener = listener;
    }


    private boolean isCheck = false;


    public void setCheck(boolean check) {
        isCheck = check;
    }


    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new AddressContactItemMenu();
    }

    public class AddressContactItemMenu implements AdapterItem<SuperviseSettingTail> {


        @Bind(R.id.textView)
        TextView textView;
        @Bind(R.id.tv_status_tip)
        TextView tvStatusTip;
        @Bind(R.id.lineAll)
        RelativeLayout lineAll;
        @Bind(R.id.txtDelete)
        TextView txtDelete;
        @Bind(R.id.all)
        SwipeMenuLayout all;
        @Bind(R.id.textViewSub)
        TextView textViewSub;
        private SuperviseSettingTail mData;
        private int mPosition;


        @Override
        public int getLayoutResId() {
            return R.layout.item_fire_company_set;
        }

        @Override
        public void bindViews(View root) {
            ButterKnife.bind(this, root);
        }

        @Override
        public void setViews() {

            txtDelete.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    FireCompanyDelete event = new FireCompanyDelete();
                    event.setTag(FireCompanyDelete.class.getName());
                    //event.setData(mData);
                    event.setData(mData);
                    event.setmPosition(mPosition);
                    AppService.getBus().post(event);
                }
            });

            lineAll.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (mListener != null) {
                        mListener.onItemClick(mData, mPosition);
                    }
                }
            });


        }

        @Override
        public void handleData(final SuperviseSettingTail data, final int position) {
            mData = data;
            mPosition = position;

            loggerHelper.json(data);
            //初始化数据
            try {
                textView.setText(mData.getCompanyName());
                if(CommonUtil.strIsEmpty(mData.getAddress())){
                    textViewSub.setText("地址:暂无详细地址");
                }else {
                    textViewSub.setText("地址:" + mData.getAddress());
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

        }

    }


}
